package com.example.permission.myjbm.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.jbmsuppliers.R;
import com.example.permission.myjbm.config.Config;
import com.example.permission.myjbm.dao.BaseAdapter;
import com.jbm.jbmsupplier.util.ExProductEntity;
import com.squareup.picasso.Picasso;

import java.util.List;


/**
 *  积分中心显示所有优惠券
 * Created by JBMhaier on 2017/3/15.
 */

public class IntegralGridAdapter  extends BaseAdapter {
    List<ExProductEntity>  arr;

    public IntegralGridAdapter(List<ExProductEntity>  arr, Context c) {
        super(c);
        this.arr=arr;
    }

    @Override
    public Object getHolder(View convertView) {
        return new MyHolder(convertView);
    }
    @Override
    protected int getLayout() {
        return  R.layout.dsy_itemintegral_grid;
    }

    @Override
    protected Object getArr() {
        return arr;
    }

    @Override
    protected void initView(Object holder, int position) {

        ((MyHolder)holder).title.setText(arr.get(position).getName());
        SpannableString string=new SpannableString(arr.get(position).getAmount()+"积分");
        string.setSpan(new ForegroundColorSpan(Color.rgb(159,159,159)),string.length()-2,string.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE	);
        ((MyHolder)holder).jifen.setText(string);
Picasso.with(c).load(Config.PHOTOPATH+arr.get(position).getPicpath()).into(((MyHolder)holder).card);
    }

    @Override
    protected void initListener(Object holder, int position) {

    }

    static  class  MyHolder {
        TextView  title,jifen;
        ImageView card;

        public MyHolder(View convertView) {
            //标题
            title=(TextView)convertView.findViewById(R.id.item_integral_title);
            //钱数
              jifen=(TextView)convertView.findViewById(R.id.item_integral_jifen);
            //卷
              card=(ImageView)convertView.findViewById(R.id.item_integral_juan);
        }
    }
}
